/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = __stat_system_count_avg.c                          */
/*  NOTE      =                                                    */
/*  DATE      = 2015/01/30 by guojq                                */
/*******************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "frcomm.h"
#include "frmem.h"
#include "frlist.h"
#include "frhash2.h"
#include "frstat_system.h"
#include "apmtest_cunit.h"

extern void __stat_system_count_avg(unsigned long arr_ul_last[4], unsigned long *p_avg);

static int __suite_init(void)
{
	return 0;
}

static int __suite_cleanup(void)
{
	return 0;
}

void case1(void)
{
    unsigned long arr_ul_last[4];
    unsigned long ul_avg = 0;

    arr_ul_last[0]=0;
    arr_ul_last[1]=0;
    arr_ul_last[2]=0;
    arr_ul_last[3]=0;
    
    __stat_system_count_avg(arr_ul_last, &ul_avg);
    
    CU_ASSERT_EQUAL(ul_avg,0);

    return;

}

void case2(void)
{
    unsigned long arr_ul_last[4];
    unsigned long ul_avg = 0;

    arr_ul_last[0]=100;
    arr_ul_last[1]=0;
    arr_ul_last[2]=0;
    arr_ul_last[3]=0;
    
    __stat_system_count_avg(arr_ul_last, &ul_avg);
    
    CU_ASSERT_EQUAL(ul_avg,0);

    return;

}

void case3(void)
{
    unsigned long arr_ul_last[4];
    unsigned long ul_avg = 0;

    arr_ul_last[0]=200;
    arr_ul_last[1]=100;
    arr_ul_last[2]=0;
    arr_ul_last[3]=0;
    
    __stat_system_count_avg(arr_ul_last, &ul_avg);
    
    CU_ASSERT_EQUAL(ul_avg,100);

    return;

}

void case4(void)
{
    unsigned long arr_ul_last[4];
    unsigned long ul_avg = 0;

    arr_ul_last[0]=700;
    arr_ul_last[1]=200;
    arr_ul_last[2]=100;
    arr_ul_last[3]=0;
    
    __stat_system_count_avg(arr_ul_last, &ul_avg);
    
    CU_ASSERT_EQUAL(ul_avg,300);

    return;

}

void case5(void)
{
    unsigned long arr_ul_last[4];
    unsigned long ul_avg = 0;

    arr_ul_last[0]=1000;
    arr_ul_last[1]=700;
    arr_ul_last[2]=200;
    arr_ul_last[3]=100;
    
    __stat_system_count_avg(arr_ul_last, &ul_avg);
    
    CU_ASSERT_EQUAL(ul_avg,300);

    return;

}

int add_suite()
{
	CU_pSuite pSuite = NULL;

	pSuite = CU_add_suite("__stat_system_count_avg 测试", __suite_init, __suite_cleanup);

	if (NULL == pSuite)
	{
		return 1;
	}

    //增加测试用例
   	CU_add_test(pSuite, "case1", case1);
   	CU_add_test(pSuite, "case2", case2);
   	CU_add_test(pSuite, "case3", case3);
   	CU_add_test(pSuite, "case4", case4);
   	CU_add_test(pSuite, "case5", case5);

    return 0;

}

int main(int argc, char **argv)
{
    fr_slab_init(52428800, "test");
    run_cunit(add_suite);
    fr_slab_destroy();
    return 0;
}